<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/8/2 0002
 * Time: 下午 12:10
 */

namespace app\admin\model;


use service\ToolsService;
use think\Db;
use think\Model;

class IndexBlock extends Model
{
    public static function index($id){
        $db = self::where(['is_deleted'=>1,'status'=>1,'id'=>$id])->order('sort asc,id asc')->find()->visible(['id','pid','title','english_title','link'])->toArray();
        if (!empty($db)){
            switch ($id){
                case '3':
                    $content = Db::name('index_block_content')->where(['pid'=>3])->value('content');
                    $db['content'] = json_decode($content,true);
                    break;
                case '4':
                    $ids = self::where(['is_deleted'=>1,'status'=>1,'pid'=>4])->order('sort asc,id asc')->column('id');
                    $content = Db::name('index_block_content')->where('pid','in',$ids)->where('type','nav')->field('pid,content')->select();
                    foreach ($content as &$v){
                        $v['content'] = json_decode($v['content'],true);
                    }
                    $db['content'] = $content;
                    break;
                case '5':
                    $content = Db::name('index_block_content')->where('pid', 5)->whereNull('type')->value('content');
                    $db['content'] = json_decode($content,true);
                    break;
                case '6':
                    $content = Db::name('index_block_content')->where('pid', 6)->whereNull('type')->value('content');
                    $db['content'] = json_decode($content,true);
                    break;
                case '7':
                    $content = Db::name('index_block_content')->where('pid', 7)->whereNull('type')->value('content');
                    $db['content'] = json_decode($content,true);
                    break;
                case '8':
                    $content = Db::name('index_block_content')->where('pid', 8)->whereNull('type')->value('content');
                    $db['content'] = json_decode($content,true);
                    break;
                case '9':
                    $content = Db::name('index_block_content')->where('pid', 9)->whereNull('type')->value('content');
                    $db['content'] = json_decode($content,true);
                    break;
                case '2':
                    $content = Db::name('index_block_content')->where(['pid'=>2])->value('content');
                    $db['content'] = json_decode($content,true);
                    break;
                case '1':
                    $content = Db::name('index_block_content')->where(['pid'=>1])->value('content');
                    $db['content'] = json_decode($content,true);
                    break;
            }
        }

        return $db;
    }
}